package com.zhuliwei.actuator;

import org.springframework.boot.actuate.health.AbstractHealthIndicator;
import org.springframework.boot.actuate.health.Health;
import org.springframework.boot.actuate.health.Status;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

/**
 *
 * @author 朱力维
 * @time 2022/10/23 17:34
 **/
@Component
public class HealthConfig extends AbstractHealthIndicator {
    @Override
    protected void doHealthCheck(Health.Builder builder) throws Exception {
        boolean condition = true;
        if (condition){
            // 设置组件的状态 UP、DOWN、OUT_OF_SERVICE(不在服务)
            builder.status(Status.UP);
            Map infoMap = new HashMap();
            infoMap.put("runTime",System.currentTimeMillis());
            infoMap.put("组件健康吗","very good！");
            builder.withDetails(infoMap);
        }else {
            builder.status(Status.DOWN);
            // 提示信息
            builder.withDetail("上线了吗？","你做梦！");
        }
    }
}
